package laserdancer.smart.com.criminalintent;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class CrimePageActivity extends AppCompatActivity {
    public static final String EXTRA_CRIME_ID = "criminalintent.CRIME_ID";
    private List<Crime> mCrimes;
    private ViewPager mViewPager;

    public static Intent newIntent(Context _context, UUID _uuid){
        Intent intent = new Intent(_context,CrimePageActivity.class);
        intent.putExtra(EXTRA_CRIME_ID,_uuid);
        return intent;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_crime_page);

        UUID _uuid = (UUID)getIntent().getSerializableExtra(EXTRA_CRIME_ID);

        mViewPager = (ViewPager) findViewById(R.id.activity_crime_pager_view_pager);
        mCrimes = CrimeLab.get(this).getCrimes();

        FragmentManager _manager = getSupportFragmentManager();

        List<CrimeFragment> _fragments=new ArrayList<>();

        for(int i=0;i<mCrimes.size();i++){
            _fragments.add(CrimeFragment.newInstance(mCrimes.get(i).getId()));
        }

        mViewPager.setAdapter(new ViewPagerAdapter(_manager,_fragments));
        mViewPager.setCurrentItem(0);

    }

    private class ViewPagerAdapter extends FragmentPagerAdapter {

        List<CrimeFragment> mCrimeFragments;

        public ViewPagerAdapter(FragmentManager _fragmentManager){
            super(_fragmentManager);
        }

        public ViewPagerAdapter(FragmentManager _fragmentManager,List<CrimeFragment> _crimeFragments){
            super(_fragmentManager);
            mCrimeFragments = _crimeFragments;
        }

        @Override
        public Fragment getItem(int position) {
            return mCrimeFragments.get(position);
        }

        @Override
        public int getCount() {
            return mCrimeFragments.size();
        }
    }

}
